<template>
    <div class="logindiv">
        <div class="tool-box"></div>
        <div class="head-box">
		<div class="comwid clearfix">
			<div class="head-logo lf">
				<a href="javaScript:;"><img src="../images/head-logo.png"></a>
                <a class="titlename" href="javaScript:;" >
                    <span class="titlenamea">内蒙古自治区</span>
                    <span class="titlenameb">测绘地理信息局电子党务系统</span>
                </a>
			</div>
		</div>
	</div>
    <div class="nav-box"></div>
    <div class="loginform"> 
        <div class="loginformb">
            <el-form :model="Valid" ref="Valid" class="forms" status-icon>
                <el-form-item prop="name" label="" :rules="[{ required: true, message: '请输入身份证号', trigger: ['blur','change'] }]">
                    <el-input v-model="Valid.name" placeholder="身份证号" class="input-with-select" clearable></el-input>
                    <span class="el-input__prefix"><i class="fa-user"></i></span>
                </el-form-item>
                <el-form-item prop="password" @keyup.13="submitForm('Valid')" label="" :rules="[{ required: true, message: '请输入密码', trigger: ['blur','change'] }]">
                <el-input type="password" v-model="Valid.password" autocomplete="off" placeholder="密码" clearable></el-input>
                <span class="el-input__prefix"><i class="fa-unlock-alt"></i></span>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary"  @click="submitForm('Valid')"  class="btclass">登陆</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</div>
</template>
<script>
    import {mapActions} from 'vuex';
    // import md5 from "../js/md5.js";
    export default {
        data() {
            return {
                Valid: {
                    name: "",
                    organizationID: "",
                    password: "",
                },
            };
        },
        mounted()
        {
            let _this=this;
            document.onkeydown=e=>{
                let _key=window.event.keyCode;
                if(_key===13){
                    this.submitForm('Valid');
                }
            }
            this.$Common.Config.this=this;
        },
        methods: {
            ...mapActions(['Login','WriteActiveDwId_DzbId','WriteActivebreadcrumb']),
            submitForm(formName) {
                this.$refs[formName].validate(valid => {
                    if (valid) {
                        this.LoginAjax();
                    }
                });
            },
            LoginAjax() {
                let postdata =  {
                    type: "login",
                    split: JSON.stringify({
                        UserName: this.Valid.name,
                        PassWord: this.Valid.password// md5(this.Valid.password)
                    })
                }
                let _this=this;
                this.$Loading.start();
                this.Login(postdata)
                .then(function(data){
                    if(data==false){
                        _this.$Loading.finish();
                        _this.$message({
                            message: '用户名或密码错误',
                            type: 'error',
                            duration:1000
                        })
                        
                    }
                    else{
                        setTimeout(function(){
                            _this.$Loading.finish();
                            // 根据权限 转到不同的vue
                            _this.routerTo(data)

                        },800);
                        
                    }  
                    
                })
            },
            routerTo(user){
                this.WriteActivebreadcrumb({
                    name:'login',
                    value:'登陆',
                })
                if(user.operation==0){//全局管理员时进入全局
                    this.WriteActiveDwId_DzbId({dwid:-1,dzbid:-1});
                    
                    this.$router.push("/view"); 
                }
                else if(user.operation==1){
                    this.WriteActiveDwId_DzbId({dwid:user.dwid,dzbid:-1});
                    this.$router.push({name: "dw",})
                }
                else if(user.operation>1){
                    this.WriteActiveDwId_DzbId({dwid:user.dwid,dzbid:user.dzbid});
                    this.$router.push({name: "classify",})
                }

            },
        },
    }
</script>
<style >

</style>